
<template>
  <el-header>
    <div class="l-content">
      <!-- 图标的展示 -->
      <el-button size="small"
                 plain
                 @click="handleCollapse">
        <el-icon size="20">
          <Menu />
        </el-icon>
      </el-button>
      <!-- 面包屑位置 -->
      <el-breadcrumb separator="/"
                     class="bread">
        <!-- 首页是一定存在的，所以直接写死 -->
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>

        <el-breadcrumb-item :to="current.path"
                            v-if="current">{{ current.label }}
        </el-breadcrumb-item>

      </el-breadcrumb>
    </div>
    <div class="r-content"><el-dropdown>
        <span class="el-dropdown-link">
          <img class="user"
               :src="getImgSrc('user')"
               alt="">
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleLoginOut">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown></div>
  </el-header>
</template>


<script>

import { computed, defineComponent } from 'vue-demi';
import { useRouter } from 'vue-router';
import { useStore } from 'vuex';
export default defineComponent({
  //vue3 如果使用到了变量 都要写到这里面
  setup () {
    let store = useStore();
    //const imgSrc = require('../assets/images/user.png');
    const getImgSrc = (user) => {
      return new URL(`../assets/images/${user}.png`, import.meta.url).href
    }
    // 左侧菜单栏  关闭开启写法
    let handleCollapse = () => {
      //调用vuex中的mutations
      store.commit('updateIsCollapse', "不知道怎么用传一个郝小雨试试");
    };
    const current = computed(() => {
      return store.state.currentMenu;
    });

    const router = useRouter();
    const handleLoginOut = () => {
      store.commit("cleanMenu");
      store.commit("clearToken");
      router.push({ name: 'login' })
    };

    return {
      getImgSrc,
      handleCollapse,
      current,
      handleLoginOut,
    }
  }
})
</script>

<style lang="less" scoped>
.el-header {
  display: flex; //布局
  justify-content: space-between; //调整间距
  align-items: center;
  width: 100%;
  background-color: #333;
}

.user {
  width: 40px;
  height: 40px;
  border-radius: 50%; //圆半角
  margin-right: 20px;
}
.l-content {
  display: flex;
  align-items: center;
  padding-left: 20px;
  .el-button {
    margin-left: 10px;
    margin-right: 15px;
  }
  // .bread /deep/span {
  //   color: #fff;
  //   cursor: pointer !important;
  // }
  :deep(.bread span) {
    color: #fff !important;
    cursor: pointer !important;
  }
}
</style>



